<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册账号</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/register.css">
</head>

<body>
    <div class="container mt-5">
        <div class="row justify-content-center">
            <div class="col-md-4">
                <h2 class="text-center mb-4">注册账号</h2>
                <form id="registerForm">
                    <div class="form-group">
                        <label for="username">用户名</label>
                        <input type="text" class="form-control" id="username" name="username" placeholder="请输入用户名"
                            required>
                    </div>
                    <div class="form-group">
                        <label for="password">密码</label>
                        <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码"
                            required>
                    </div>
                    <div class="form-group text-center mt-4">
                        <button type="button" class="btn btn-primary btn-block" onclick="register()">注册</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="js/jquery.min.js"></script>
    <script>
        function register() {
            $.ajax({
                type: "POST",
                url: "/user/register",
                data: $("#registerForm").serialize(),
                success: function (result) {
                    if (result.code === 200) {
                        alert('注册成功！');
                        location.href = "login.html"; // 跳转到登录页面
                    } else {
                        alert(result.message || '注册失败，请重试！');
                    }
                },
                error: function (error) {
                    alert('请求失败，请稍后重试！');
                }
            });
        }
    </script>
</body>

</html>